package Haak::C::Youtube;

use strict;
use warnings;
use base qw( Haak );
use LWP::UserAgent;

sub do_default {
    my $self = shift;
}

sub do_result {
    my $self = shift;

    my $url = $self->req->param('url');
    my $ua = LWP::UserAgent->new;

    my $response = $ua->get($url);
    
    warn $url;
    return $self->forward('default') unless $response->is_success;
    my $content = $response->content;

    if($content =~ /video_id=(.+?)&.*?&t=(.+?)&/){
        my $mp4_url = "http://www.youtube.com/get_video?video_id=$1&t=$2&fmt=18";
#        warn "downloading mp4 from $mp4_url\n";
        $self->res->redirect($mp4_url);
    }else{
        warn "Error\n";
    }

}

1;

=head1 NAME

Haak::C::Youtube - Soozy Component

=head1 SYNOPSIS

See L<Haak>

=head1 DESCRIPTION

Soozy Component

=head1 AUTHOR

JEEN

=head1 LICENSE

This library is free software, you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut
